﻿using System;
using System.Windows.Forms;

namespace ajayumi.develop.win32.Transport.Client.WinForm
{
    public partial class FrmMain : Form
    {
        #region Variables


        #endregion

        public FrmMain()
        {
            InitializeComponent();

            this.ucUpload1.Display = (text) =>
            {
                this.AppendText(this.txtMsg, text);
            };
            this.ucDownload1.Display = (text) =>
            {
                this.AppendText(this.txtMsg, text);
            };

            ////隐藏 上传、下载 选项卡
            //this.TabPage1.Parent = null;
            //this.tabPage3.Parent = null;
            //this.tsmiSetting.Visible = false;
            //this.toolStripSeparator1.Visible = false;

            this.FormClosing += (sender, e) =>
            {
                //TransTaskManager.Instance.Save();
                System.Environment.Exit(System.Environment.ExitCode);
            };
        }

        /// <summary>
        /// 追加反馈信息
        /// </summary>
        /// <param name="control"></param>
        /// <param name="text"></param>
        private void AppendText(TextBox control, string text)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(new Action<TextBox, string>(this.AppendText), new object[] { control, text });
            }
            else
            { control.AppendText(text); }
        }


        private void FormVisible_Click(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Hide();
            }
            else
            {
                this.Show();
            }
        }

        private void tsmiExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.tsmiShow.PerformClick();
        }

        private void tsmiSetting_Click(object sender, EventArgs e)
        {
            FrmSetting frmSetting = new FrmSetting();
            frmSetting.ShowDialog();

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void FrmMain_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.notifyIcon1.Visible = false;
            }
            else
            {
                this.notifyIcon1.Visible = true;
            }
        }

    }



}
